package http

const (
	// Success diy code
	Success = 0 // success 除开code 为 0 的其余全是错误的code

	Error            = 1 // error
	StatusOK         = 200
	StatusBadRequest = 400

	TokenExpired = -99 // token 过期
)

type BaseResponse struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
}

type Response struct {
	BaseResponse

	Data interface{} `json:"data"`
}

func SuccessRes() Response {
	return Response{BaseResponse: BaseResponse{Code: Success, Msg: "success!"}}
}

func SuccessResData(data interface{}) Response {
	return Response{BaseResponse: BaseResponse{Code: Success, Msg: "success!"}, Data: data}
}
func SuccessResWithToken(token string) ResponseWithToken {
	return ResponseWithToken{BaseResponse: BaseResponse{Code: Success, Msg: "success!"}, Token: token}
}

func FailureResDefaultCode(message string) Response {
	return Response{BaseResponse: BaseResponse{Code: Error, Msg: message}}
}

func LoginExpire(message string) Response {
	return Response{BaseResponse: BaseResponse{Code: TokenExpired, Msg: message}}
}

type ResponseWithToken struct {
	BaseResponse
	Token string `json:"token"`
}
